#lang rosetta-racket


(provide spherical-tear)


(define (inverted-cone r h th fi)
  (rotate th uz
          (rotate fi ux
                  (move
                   (*c uz h)
                   (rotate pi ux (cone r h))))))

(define (spherical-tear ri re r h n)
  (let ((s (subtract (sphere ri) (sphere re))))
    (for/list ((fi (: < 0 .. < (/2 n) > .. pi >)))
      (for/list ((th (: < 0 .. < (+ n (floor (* n (sin fi)))) > .. 2pi >)))
        (let ((r (+ r (* r (sin fi)))))
          (set! s (subtract s (inverted-cone r h th fi))))))
    s))